//
//  dataBase.h
//  ElektroM
//
//  makes all the work with data base SQLite
//  Created by Michael on 10.10.09.
//  Copyright 2009 Artgruppe inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <sqlite3.h>

@interface dataBase : NSObject {	
	NSString* databaseName;
	NSString* databasePath;	
	NSString* namePrefix;
	
	int 		nCentersCount;
	
	//stations:
	int 		nStationsCount;
	
	int 		nTimeTableCount;
	NSArray* 	_aiStationsNames;	
	int* 		_anTrainInfo;
	
	// for the names of starting and ending 
	// stations:
	NSArray* 	_aiCentersX;
	NSArray* 	_aiCentersY;

	// structure:
	NSArray*	_aiNext;
	NSDictionary* 	_diNodes;

	NSArray*	_aiStartStations;
	NSArray*	_aiEndStations;
	NSArray*	_aiTimes;
	NSArray*	_aiTrainIds;
	NSArray*	_aiiTrainInfo;
	bool 		_bReloadDayAndNight;

	// as NSArray;
	NSArray*	_aiBusInfo;
	NSArray* 	_aiBusNames;
	NSArray* 	_aiBusTimes;
	int 		_nBusCount;
	bool 		_bReloadTimes;
	
	// train Info:
	NSArray* 	_aiTrainTimes;
	NSArray*	_aiTrainStations;
	NSUInteger 	_nTrainTimesCount;
	NSArray* 	_aiStationsNamesForTrains;
	NSString* 	_sDestinationTime;
	
	/// U-Stations:
	NSUInteger _nUStationsCount;
	NSUInteger* _nULinesNumbers;

	NSUInteger 	_nUStationNotShownCount;
	bool 		_bStationsInAlpabeticalOrderWereLoaded;
	//iApple-style:
	//
	NSDictionary* 	_diULineNumbers;
	NSDictionary* 	_diUStationNumbers;
	NSArray*	_aiAllStationsShown;
	NSArray* 	_aiAllStationsIds;
	NSArray*	_aiAllStationsLineIds;
	NSArray* 	_aiStationIdsForLineSorting;
	NSDictionary* 	_diStationIds;
	NSArray*	_aiLineIds;
	//----- U-Bahn and its lines ----
	NSArray* 	_aiUStations;
	NSArray* 	_aiULineNames;
	NSArray*	_aiiULineNumbers;
	NSArray* 	_aiiUStationIds;
	NSArray* 	_aiiUStationsNotShown;

	NSArray* 	_aiUCentersX;
	NSArray* 	_aiUCentersY;

	NSArray* 	_aiDrawInfo;


	// cyclon data (objective-C):
	
	NSArray* 	_aiNodes;
	NSArray* 	_aiCyclonLineNubmers;

	// sightseeing:
	NSArray* 	_aiSightCaptions;
	NSArray* 	_aiSightDetail;
	NSArray* 	_aiSightTypes;
	NSArray* 	_aiSightStationId;
	// for main metro scheme:
	NSArray* 	_aiSSStationIds;
	int 		_nAmountSightSeeing;

	int _bUseEnglishNames;
	int _nCountOfAllowedLines;
}

@property (nonatomic, retain) NSString* namePrefix;
@property (nonatomic, retain) NSString* databaseName;
@property (nonatomic, retain) NSString* databasePath;

-(int) getStationsCount;
-(int) getTimeTableCount;
-(void) checkAndCreateDatabase;
-(void) initialization;

-(NSArray*) readCentersAsNSArray;
-(NSArray*) getCentersXAsNSArray;
-(NSArray*) getCentersYAsNSArray;

-(NSArray*) getStationNamesAsNSArray;
-(NSArray*) readStationNamesAsNSArray;

// small version for updating labels:
-(NSString*) readTimeTableByCenterIdShort:(int)nCenterId withDirection:(int)nDirection;
-(NSString*) readStationNameByCenterId:(int)nCenterId;

-(NSString*) separateByColonesAndAddToQuery:(NSString*)sQuery splittingString:(NSString*)sString andFirst:(bool)bFirstIn;
-(void) releaseBusInfoResources;
-(NSArray*) readBusesInfoBySearchAsNSArray: (NSString*)sSearch;
-(NSArray*) getBusesTimesAsNSArray;
-(NSArray*) getBusesInfoAsNSArray;


-(NSUInteger) getUStationsCount;
-(NSDictionary*) getULineNumbersSortedAlp;
-(NSDictionary*) getUStationNumbersSortedAlp;
-(NSArray*) getAllStationsNameInAppleFormat;
-(NSArray*) getAllStationsIdsInAppleFormat;
-(NSArray*) getAllStationsLineIdsInAppleFormat;
-(NSDictionary*) readUStationsAndOrderThemByLineNames;
-(NSDictionary*) getUStationIdsSortedByLine;
-(NSArray*) getUStationsLineIdsUsedInStationsSortedByLine;
-(NSArray*) readUStationsDrawInfoAsNSArray;
-(NSArray*) readUStationsAsNSArray;
-(NSArray*) getUStationIdsAsNSArray;
-(NSArray*) getUStationNotShownAsNSArray;
-(NSArray*) getULineNamesAsNSArray;
-(NSArray*) getULineNumbersAsNSArray;
-(NSArray*) readUStationsAsNSArrayAndOrderAlpabetically: (bool)alp;
-(NSDictionary*) readUStationsAsNSArrayAndFormThemAlpabetically;
-(void) releaseUStationAsNSArrayResources;
-(void) releaseAllElementsOfTimeTableAsNSArray;
-(NSArray*) readTimeTableAsNSArray:(int)nStation_id withTime:(NSString*)aCurTime withDirection:(int)nDirection;
-(NSArray*) getStartStationsAsNSArray;
-(NSArray*) getEndStationsAsNSArray;
-(NSArray*) getTrainInfoAsNSArray;
-(NSArray*) getTrainIdsAsNSArray;
-(NSArray*) readStationStructureAsNSArrayAndLoadAlsoNames:(bool)bLoadNames;
-(NSDictionary*) getNodesOfStationsAsNSArray;
-(NSArray*) getSightseeingForNumbers:(NSArray*)aiNumbers;
-(NSArray*) getSightTypes;
-(NSArray*) getSightDetails;
-(NSArray*) getSightCaptions;
-(void) releaseAllSightSeeing;
-(NSArray*) getSightStationIds;
// those functions are only needed in main screen of Metro
-(NSArray*) getSightseeingAllStationIdsOnly;
-(void) releaseAllSightSeeingStationIDs;
-(int) getAmountOfSightSeeingStationIds;
-(NSArray*) getTrainStations;
-(NSArray*) readTrainInfoAsNSArray:(NSString*)trainId;
-(void) cleanTrainInfoAsNSArray;
-(NSArray*) getTrainStationsNames;
-(NSString*) findTimeOfNearTrainWithFirstSt:(int)nFirstSt 
			   andSecondStation:(int)nSecond 
			      withDirection:(int)nDirection;
-(NSString*) getDestinationTime;
-(NSArray*) getCycloneLineNumbers;
-(NSArray*) readUStationToStationStructure;
-(NSArray*) readCentersAsNSArrayLoadRailways:(bool)bRailways;
-(NSArray*) getUCentersYAsNSArray;
-(void) cleanCentersInfo;
-(NSString*) separateByColonesAndAddToQueryName:(NSString*)sQuery splittingString:(NSString*)sString andFirst:(bool)bFirstIn;
-(NSUInteger) getUStationsCountOfAllowedLinesWithStart: (int) nStart andEnd: (int) nEnd;
-(int*) getUStationsAllowedLinesWithStart: (int) nStart andEnd: (int) nEnd andIndex: (int) nIndex;
-(int) getUStationsCountOfAllowedLinesArray;
-(NSString*) findTimeOfNearTrainWithFirstSt:(int)nFirstSt 
						   andSecondStation:(int)nSecond 
							  withDirection:(int)nDirection
								andTimeZero: (bool)bZero;
-(void) cleanAllResourcesOfUStationNamesWithAlpOrd;
-(void) releaseUStation2StationResources;
@end
